package com.farm.farm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.farm.common.annotation.Log;
import com.farm.common.core.controller.BaseController;
import com.farm.common.core.domain.AjaxResult;
import com.farm.common.enums.BusinessType;
import com.farm.farm.domain.Farm;
import com.farm.farm.service.IFarmService;
import com.farm.common.utils.poi.ExcelUtil;
import com.farm.common.core.page.TableDataInfo;

/**
 * 农场地管理Controller
 * 
 * @author yd
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/farm/farm")
public class FarmController extends BaseController
{
    @Autowired
    private IFarmService farmService;

    /**
     * 查询农场地管理列表
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:list')")
    @GetMapping("/list")
    public TableDataInfo list(Farm farm)
    {
        startPage();
        List<Farm> list = farmService.selectFarmList(farm);
        return getDataTable(list);
    }

    /**
     * 导出农场地管理列表
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:export')")
    @Log(title = "农场地管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Farm farm)
    {
        List<Farm> list = farmService.selectFarmList(farm);
        ExcelUtil<Farm> util = new ExcelUtil<Farm>(Farm.class);
        util.exportExcel(response, list, "农场地管理数据");
    }

    /**
     * 获取农场地管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:query')")
    @GetMapping(value = "/{farmId}")
    public AjaxResult getInfo(@PathVariable("farmId") Long farmId)
    {
        return success(farmService.selectFarmByFarmId(farmId));
    }

    /**
     * 新增农场地管理
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:add')")
    @Log(title = "农场地管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Farm farm)
    {
        return toAjax(farmService.insertFarm(farm));
    }

    /**
     * 修改农场地管理
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:edit')")
    @Log(title = "农场地管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Farm farm)
    {
        return toAjax(farmService.updateFarm(farm));
    }

    /**
     * 删除农场地管理
     */
    @PreAuthorize("@ss.hasPermi('farm:farm:remove')")
    @Log(title = "农场地管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{farmIds}")
    public AjaxResult remove(@PathVariable Long[] farmIds)
    {
        return toAjax(farmService.deleteFarmByFarmIds(farmIds));
    }
}
